package com.dev.elasticsearch.service;

import com.dev.elasticsearch.entity.Dictionary;
import com.dev.elasticsearch.mapper.DictionaryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @ClassName : DictionaryServiceImpl  //类名
 * @Description :   //描述
 * @Author :   //作者
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Override
    public boolean existsById(String id) {
        return dictionaryMapper.existsById(id);
    }

    @Override
    public Iterable<Dictionary> list(Dictionary entity) {
        return dictionaryMapper.findAll();
    }

    @Override
    public Dictionary save(Dictionary entity) {
        return dictionaryMapper.save(entity);
    }

    @Override
    public Optional<Dictionary> findById(String id) {
        return dictionaryMapper.findById(id);
    }

    @Override
    public Dictionary updateById(Dictionary entity) {
        boolean b = this.existsById(entity.getDictId());
        return b ? dictionaryMapper.save(entity) : null;
    }

    @Override
    public void removeById(String id) {
        dictionaryMapper.deleteById(id);
    }

    @Override
    public void remove(Dictionary entity) {
        dictionaryMapper.delete(entity);
    }

    @Override
    public void removeAll() {
        dictionaryMapper.deleteAll();
    }

    @Override
    public long count() {
        return dictionaryMapper.count();
    }
}
